<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="org.swimv2.sessions.JobsManager"%>
<%@ page import="org.swimv2.entities.*" %>
<%@ page import="java.text.SimpleDateFormat" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
User curr_u = (User) request.getSession().getAttribute("user");
Job       j = (Job)  request.getAttribute("page_job");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); 
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style type="text/css">
@import url(/WEBswim2/css/main.css);
</style>
    <title>Show Job</title>
</head>
<body>

<p class="homenav"><a href="/WEBswim2/home.jsp"><span>Home</span></a></p>
<% if (curr_u != null) { %>
<ul class="ul_nav">
    <li><a href="/WEBswim2/user/profile.jsp">Il Mio Profilo</a> <em>[<% out.print(curr_u.getFirstName() +" "+ curr_u.getLastName()); %>]</em></li>
    <% if (curr_u.getIsAdmin()) { %><li><a href="/WEBswim2/admin/profile.jsp">Pannello di controllo Amministratore</a></li><% } %>
    <li><a href="/WEBswim2/Logout">Logout</a></li>
</ul>
<% } %>

<h1>Visualizza dettaglio lavoro</h1>
<%
    String msg = (String) request.getAttribute("message");
    if (msg != null) {
        out.println("<p class=\"message\">"+ msg +"</p>");
    }
    String err = (String) request.getAttribute("error_message");
    if (err != null) {
        out.println("<p class=\"error_message\">"+ err +"</p>");
    }
%>

<p>
<% if (j != null) { %>
    <strong>Cliente:</strong>
    <% out.print("<a href='/WEBswim2/user/show.jsp?user_id="+ j.getClient().getId() +"'>"
                 + j.getClient().getFirstName() +" "+ j.getClient().getLastName() +"</a><br/>"); %>
    <strong>Lavoratore:</strong>
    <% out.print("<a href='/WEBswim2/user/show.jsp?user_id="+ j.getWorker().getId() +"'>"
    		     + j.getWorker().getFirstName() +" "+ j.getWorker().getLastName() +"</a><br/>"); %>
    <strong>Luogo lavorativo:</strong>
    <% out.print(j.getPlace() +"<br/>"); %>
    <strong>Data di inizio lavori:</strong>
    <% out.print( dateFormat.format(j.getStartDate()) +"<br/>" ); %>
    <strong>Data di fine lavori:</strong>
    <% if (j.getEndDate() != null) out.print( dateFormat.format(j.getEndDate()) +"<br/>" ); %>
    <strong>Competenza richiesta:</strong>
    <%= j.getSkill().getName() %><br/>
    <strong>Paga (&euro;):</strong>
    <% out.print(j.getPay()); %><br/>
    <p><strong>Descrizione del lavoro:</strong><br/><% out.print(j.getDescription()); %></p>
    <strong>STATO: <% out.print(j.getStatus()); %></strong><br/>
    <%
    if (j.getStatus().equals(JobsManager.CLOSED) && j.getFeedback() != null) {
    	out.println("<strong>Feedback</strong>:");
    	out.println("<em>"+ j.getFeedback().getRating() +" stelle</em><br/>");
    	out.println(j.getFeedback().getDescription());
    } else if(j.getStatus().equals(JobsManager.INPROGRESS) && j.getFeedback() == null && curr_u != null && j.getClient().getId() == curr_u.getId()) {
        out.println("<strong><a href='/WEBswim2/LeaveFeedback?job_id="+ j.getId() +"'>Inserisci Feedback</a></strong>");
    }
    %>
<% } // if j not null %>


</body>
</html>